package org.mayuanxiaonong.timserver.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import org.mayuanxiaonong.timserver.handler.deliver.DeliverQueue;
import org.mayuanxiaonong.timserver.packet.MessagePacket;
import org.mayuanxiaonong.timserver.packet.Packet;
import org.mayuanxiaonong.timserver.packet.PresencePacket;

/**
 * 服务器主要处理器
 * 
 * @author 9527
 *
 */
public class ServerHandler extends SimpleChannelInboundHandler<Packet> {

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, Packet packet)
			throws Exception {

		switch (packet.getType()) {
		case Packet.Type.MESSAGE:
			DeliverQueue.deliver((MessagePacket) packet);
			break;
		case Packet.Type.PRESENCE:
			DeliverQueue.deliver((PresencePacket) packet);
			break;
		default:
			// log.error("type error " + packet.toString());
			break;
		}
	}

}
